package org.cmisarium.xcmis.fsprovider;

import java.io.File;
import java.io.IOException;

import org.xcmis.spi.Connection;
import org.xcmis.spi.PermissionService;
import org.xcmis.spi.TypeManager;
import org.xcmis.spi.basic.BasicConnection;
import org.xcmis.spi.basic.BasicStorageProvider;

public class StorageProviderImpl extends BasicStorageProvider
{

   protected static String REPOSITORY_DESCRIPTION = "Demo xCMIS repository";

   protected final File rootFolder;

   protected final TypeManager typeManager;

   protected final String repositoryId;

   protected PermissionService permissionService;

   public StorageProviderImpl(String rootPath, String repositoryId, String repositoryName) throws IOException
   {

      super(repositoryId, repositoryName, PathCoder.pathToId(new File(rootPath).getAbsolutePath()));

      rootFolder = new File(rootPath);
      if (!rootFolder.exists() || !rootFolder.isDirectory())
         throw new IOException("Path " + rootFolder.getAbsolutePath() + " does not exist or not a folder");

      this.typeManager = new TypeManagerImpl();

      this.repositoryId = repositoryId;

      this.permissionService = new PermissionService();

   }

   public Connection getConnection()
   {

      return new BasicConnection(new StorageImpl(rootFolder, repositoryInfo, typeManager, this.permissionService));
   }

   public String getStorageID()
   {

      return repositoryId;
   }

   //  public void addRenditionProvider(Object arg0) {
   //	// TODO Auto-generated method stub
   //	
   //  }

}
